home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / dino / dino_bot.1 / examples / matvec / ex6.d < prev    next >
Encoding:
Text File  |  1991-03-10  |  1.7 KB  |  74 lines

  1. /* Copyright, 1990, Regents of the University of Colorado */
  2. /* This program computes a matrix - vector product, dividing the matrix into
  3.  * columns, with multiple columns per processor. The matrix is of size M x N,
  4.  * where N must be a multiple of P. */
  5.  
  6. #include "dino.h"
  7.  
  8. #define P 3
  9. #define M 16
  10. #define N 9
  11.  
  12. environment node[P:id] {
  13.  
  14.   composite matvec (in a, in x, out y)
  15.   double distributed a[M][N] map BlockCol;      /* Input matrix */
  16.   double distributed x[N] map Block;            /* Input vector */
  17.   double distributed y[M] map all;              /* Result vector */
  18.  
  19.   {
  20.     int i, j;                   /* Looping variable */
  21.  
  22.     /* Each processor computes a contribution to the final result y[] */
  23.     for (i = 0; i < M; i++) {
  24.       y[i] = 0;
  25.       for (j = id * N/P; j < (id + 1) * N/P; j++)
  26.         y[i] += a[i][j] * x[j];
  27.     }
  28.  
  29.     /* Now, we do a sum across all processors to compute the final result */
  30.     y[] = gsum(y[])#;
  31.  
  32.   }
  33. }
  34.  
  35. environment host {
  36.  
  37.   double a[M][N];
  38.   double x[N];
  39.   double y[M];
  40.  
  41.   void main ()
  42.  
  43.   {
  44.     int i, j;           /* Looping variables */
  45.  
  46.     /* Set up the initial data for a[][] and v[] */
  47.     for (j = 0; j < N; j++) {
  48.       x[j] = j;
  49.       for (i = 0; i < M; i++)
  50.         a[i][j] = i + j;
  51.     }
  52.  
  53.     /* Print out the initial data */
  54.     printf ("Initial data for a:\n");
  55.     for (i = 0; i < M; i++) {
  56.       for (j = 0; j < N; j++)
  57.         printf ("%6.2f", a[i][j]);
  58.       printf ("\n");
  59.     }
  60.  
  61.     printf ("\nInitial data for x:\n");
  62.     for (i = 0; i < N; i++)
  63.       printf ("%6.2f\n", x[i]);
  64.  
  65.     /* Perform the computation */
  66.     matvec (a[][], x[], y[])#;
  67.  
  68.     /* Printout the resulting vector y */
  69.     printf ("\nResult data for y:\n");
  70.     for (i = 0; i < M; i++)
  71.       printf ("%6.2f\n", y[i]);
  72.   }
  73. }
  74.